/* test Fibonacci Heap */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "mex.h"
#include "fibheap.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, 
  const mxArray *prhs[]) {
    
    fibHeap *h;
    fibNode **node, *tmp;
    DoublyLinkedList* l;
    DoublyLinkedNode *no;
    int n_nodes, i;
    double num;
    
    h = make_fibheap();
     
    srand(time(NULL));
    
    n_nodes = 10;
    node=malloc(sizeof(fibNode *)*n_nodes);
    
    for (i=0; i<n_nodes; i++) {
        num = (double) (rand() % 100) + 1;
        mexPrintf("%f\n", num);
        
        node[i] = make_fibnode(num);
    }
    
    l = dll_new_list();
    
    //dll_insertBeginning(l, node[0]->lnode);
    for (i=0; i<n_nodes; i++) {
        fibheap_insert(h, node[i]);
        mexPrintf("Fibheap Min: %f\n",fibheap_minimum(h));
    }
    
    fibheap_decreasekey(h, node[2], 10);
    
    for (i=0; i<n_nodes+10; i++) {
        tmp = fibheap_extractmin(h);
        
        if (tmp != NULL)
            printf("Fibheap key extracted: %f\n", tmp->key);
        
        if (h->minNode != NULL)
            mexPrintf("Fibheap Min: %f\n",fibheap_minimum(h));
    }
    
    free(node);
    
}
